<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>

<head>
    <meta charset="utf-8">
    <title>
        后台管理系统
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/x-admin.css" media="all">
</head>

<body>
<div class="x-body">

        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>旧密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass" name="password" required="" lay-verify="pass"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                1到12个字符，不能有特殊符号
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="x-red">*</span>新密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass1" name="password1" required="" lay-verify="pass"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                1到12个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_repass" name="password2" required="" lay-verify="repass"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" onclick="requestJson()" >修改</button>
        </div>

    <label for="L_repass" class="layui-form-label">
    </label>
    <div class="layui-btn" >

    </div>
</div>

</div>
<script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8">
</script>
<script src="${pageContext.request.contextPath}/js/x-layui.js" charset="utf-8">
</script>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form()
            ,layer = layui.layer;

        //自定义验证规则
        form.verify({
            nikename: function(value){

            }
            ,pass: [/(.+){1,12}$/, '密码必须1到12位']
            ,repass: function(value){
                if($('#L_pass1').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
        });

    });
</script>
<script src="${pageContext.request.contextPath}/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
    function requestJson(){

        var password =$("#L_pass").val();//#是id选择器
        var password1 =$("#L_pass1").val();
        var password2 =$("#L_repass").val();
        if(password==""){
            alert("原密码不能为空！");
            return false;
        }
        else if(password1==""){
            alert("新密码不能为空！");
            return false;
        }
        else if(password2==""){
            alert("确认密码不能为空！");
            return false;
        }
        else if(password1!=password2){
            alert("两次输入的密码不相等！请重新输入");
            return false;
        }
        else
        {
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath}/admin/alter_ps',
                dataType:"json",//注意使用的是打他dataType，而不是Content-Type
                async: true,
                data:{password:password,password1:password1,password2:password2},
                success:function(data){
                    if(data==0){
                        alert("修改成功！")
                        window.location.href ="${pageContext.request.contextPath}/admin/login";
                    }
                    else if(data==1){
                        alert("旧密码输入错误！")
                    }
                    else if (data==-500){
                        alert("网络繁忙，请稍后再试！")

                        window.location.href ="${pageContext.request.contextPath}/admin/index";

                    }
                }
            });
        }
    }
</script>
</body>

</html>